<?php
namespace app\blog\controller;

use app\common\controller\Base;

class Front extends Base
{
    //继承上级
    protected function initialize()
    {
        parent::initialize();
        
        $this->authCheck();

        if($this->site['action'] == 'index'){
            model('common/User','loglic')->pidSet();
        }
        
        if($this->request->isMobile()){
            $this->site['theme']  = config('channel.theme_wap');
        }else{
            $this->site['theme']  = config('channel.theme');
        }

        $this->site['pathView']   = $this->site['rootUrl'].'/view/'.$this->site['theme'];

        $this->view->config('view_base', './view/'.$this->site['theme'].'/');

        $this->assign($this->user);
    }

    //积分验证
    protected function scoreValidate($scoreTotal=0)
    {
        $modelScore = model('common/Score','loglic');
        if( !$modelScore->validateConfig($this->user['user_score'], $scoreTotal) ){
            $this->error($modelScore->getError(),'user/index/index');
        }
    }

    //SEO全局替换
    protected function seoReplace($string='',$siteTitle=false)
    {
        if(!$string){
            return '幸福文章管理系统（GxCms）';
        }
        if($siteTitle){
            $string = str_replace('[siteTitle]','',$string).'－[siteTitle]';
        }
        $search = ['[siteName]', '[siteTitle]','[siteDomain]', '[page]', '[searchText]'];
        $replace = [config('site.name'), config('site.title'), config('site.host'), $this->query['page'], $this->query['searchText']];
        return str_replace($search, $replace, xfTrim($string));
    }
}